package com.fanghuaman.model.common.vo;

import com.fanghuaman.model.common.emus.HttpEmus;
import lombok.Data;

/**
 * @author shiminghui
 * @date 2024/11/24 15:32
 * @description: 统一返回结果
 */
@Data
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;
    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(HttpEmus.SUCCESS.getCode(), HttpEmus.SUCCESS.getMsg(), data);
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(HttpEmus.SUCCESS.getCode(), msg, data);
    }

    public static <T> ResponseResult<T> success(Integer code,String msg, T data) {
        return new ResponseResult<>(HttpEmus.SUCCESS.getCode(), msg, data);
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(HttpEmus.SUCCESS.getCode(), HttpEmus.SUCCESS.getMsg(), null);
    }

    public static <T> ResponseResult<T> fail(Integer code, String msg) {
        return new ResponseResult<>(code, msg, null);
    }

    public static <T> ResponseResult<T> fail(String msg) {
        return new ResponseResult<>(HttpEmus.FAIL.getCode(), msg, null);
    }

    public static <T> ResponseResult<T> fail(Integer code, String msg, T data){
        return new ResponseResult<>(code, msg, data);
    }

    public static <T> ResponseResult<T> fail(HttpEmus emus){
        return new ResponseResult<>(emus.getCode(), emus.getMsg(), null);
    }
}
